package com.seednia.module.core.user.service;

import java.util.List;

import com.seednia.foundation.framework.dto.QueryParams;
import com.seednia.foundation.framework.dto.QueryResult;
import com.seednia.foundation.framework.service.IDataOrientedService;
import com.seednia.foundation.framework.service.RequestContext;
import com.seednia.foundation.framework.service.ServiceException;
import com.seednia.module.core.resource.dto.MediaDto;
import com.seednia.module.core.user.dto.UserCriteria;
import com.seednia.module.core.user.dto.UserDto;

/**
 * Interface for internal user service
 * @author Young Suk Ahn
 *
 */
public interface IUserService extends IDataOrientedService {

	/**
	 * Gets a single user given a criteria that maps to a unique entry
	 * 
	 * @param requestContext
	 * @param criteria
	 * @return
	 * @throws ServiceException
	 */
	UserDto getUser(RequestContext requestContext, UserCriteria criteria) throws ServiceException;

	/**
	 * Gets the user of specified sid
	 * @param requestContext
	 * @param sid
	 * @return
	 * @throws ServiceException
	 */
	UserDto getUserBySid(RequestContext requestContext, long sid) throws ServiceException;

	/**
	 * Lists the User
	 * @param criteria  The criteria used to retrieve the list (considered fields: )
	 * @return The list of records based on the criteria
	 * @throws ServiceException
	 */
	List<UserDto> getUserList(RequestContext requestContext, UserCriteria criteria, QueryParams params) throws ServiceException;
	
	/**
	 * Retrieves lists records based on the criteria (same as getPostList) and additionally
	 * returns other information, e.g. the total number of post with that criteria,
	 * @param criteria  The criteria used to retrieve the list (considered fields: )
	 * @return The list of records based on the criteria
	 * @throws ServiceException
	 */
	QueryResult<UserDto> queryPost(RequestContext requestContext, UserCriteria criteria, QueryParams params) throws ServiceException;
	
	/**
	 * Inserts a User
	 * @param record 	The record to be inserted
	 * @return the SID of the newely inserted record
	 * @throws ServiceException
	 */
	Long insertUser(RequestContext requestContext, UserDto record)  throws ServiceException;
	
	/**
	 * Updates a User
	 * @param record	The record to be updated. Pre condition: all the values must be valid
	 * @return 			The number of affected rows
	 * @throws ServiceException
	 */
	int updateUser(RequestContext requestContext, UserDto record) throws ServiceException;
	
	/**
	 * Deletes a User
	 * @param criteria	The criteria used to delete in the table (considered fields: )
	 * @return			The number of affected rows
	 * @throws ServiceException
	 */
	int deleteUser(RequestContext requestContext, UserCriteria criteria) throws ServiceException;
	
	////////// Additional Business Operations //////////
	
	/**
	 * Changes the profile/cover image
	 * @param requestContext
	 * @param domainSid
	 * @param which either 'profile' or 'cover'
	 * @param media
	 * @return
	 * @throws ServiceException
	 */
	int updateUserProfileImage(RequestContext requestContext, long userSid, String which, MediaDto media) throws ServiceException;

	/**
	 * Updates the active project
	 * @param requestContext
	 * @param userSid
	 * @param activeProjectSid
	 * @return
	 * @throws ServiceException
	 */
	public int updateActiveProject(RequestContext requestContext, long userSid, long activeProjectSid) throws ServiceException;
}
